package jdbc;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Scanner;

/*
* 删除指定用户
* 程序启动后要求用户输入用户名，然后将userinfo表中的该用户进行删除
*
* DELETE FROM userinfo
* WHERE name='?'
* */
public class Test1 {
    public static void main(String[] args) {
        try {
            System.out.println("请输入要删除的用户名称");
            Scanner scanner = new Scanner(System.in);
            String line = scanner.nextLine();
            Connection connection = DBUtile.getConnection();
            Statement statement = connection.createStatement();
            String sql = "DELETE FROM userinfo " +
                    " WHERE username='"+line+"'";
            statement.executeUpdate(sql);
            System.out.println("删除成功");
            connection.close();
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
    }
}
